﻿using learn_jquery_file_upload.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace learn_jquery_file_upload.Controllers
{
    public class BasicController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public JsonResult Upload(IFormFile files)
        {
            var resultList = new List<UploadFilesResult>();
           
            UploadFilesResult uploadFiles = new UploadFilesResult();
            uploadFiles.Name = files.FileName + " HaHa";
            uploadFiles.Size = files.Length;
            uploadFiles.Type = "image/jpeg";
            uploadFiles.Url = "/uploads/" + files.FileName;
            uploadFiles.DeleteUrl = "/Home/Delete?file=" + files.FileName;
            uploadFiles.ThumbnailUrl = "/uploads/" + files.FileName;
            uploadFiles.DeleteType = "GET";

            resultList.Add(uploadFiles);
            return Json(new { files = resultList });
        }
    }
}
